﻿using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.XtraBars;

namespace Future.FormBase
{
    public class SkinTools
    {
        /// <summary>
        /// 加载皮肤列表
        /// </summary>
        /// <param name="owner"></param>
        public static void LoadSkinList(BarSubItem owner)
        {
            foreach (DevExpress.Skins.SkinContainer skin in DevExpress.Skins.SkinManager.Default.Skins)
            {
                BarButtonItem item = new BarButtonItem(owner.Manager, skin.SkinName);
                item.ItemClick += new ItemClickEventHandler(item_ItemClick);
                owner.ItemLinks.Add(item);
            }
        }
        /// <summary>
        /// 加载皮肤列表
        /// </summary>
        /// <param name="owner"></param>
        public static void LoadSkin(DevExpress.XtraEditors.ComboBoxEdit owner)
        {
            foreach (DevExpress.Skins.SkinContainer skin in DevExpress.Skins.SkinManager.Default.Skins)
            {
                owner.Properties.Items.Add(skin.SkinName);
            }
        }

        static void item_ItemClick(object sender, ItemClickEventArgs e)
        {
            SetSkin(e.Item.Caption);
            Settings.SystemConfig.CurrentConfig.SkinName = e.Item.Caption;
            Settings.SystemConfig.WriteSettings(Settings.SystemConfig.CurrentConfig);
        }

        /// <summary>
        /// 设置所有窗体皮肤
        /// </summary>
        /// <param name="skinName"></param>
        public static void SetSkin(string skinName)
        {
            for (int i = 0; i < System.Windows.Forms.Application.OpenForms.Count; i++)
            {
                System.Windows.Forms.Form frm = System.Windows.Forms.Application.OpenForms[i];

                if (frm is frmBase)
                    (frm as frmBase).m_DefaultLookAndFeel.LookAndFeel.SkinName = skinName;
            }
        }
    }
}
